/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rw.magallanes.ide.action;

import com.rw.magallanes.core.Category;
import com.rw.magallanes.core.Warehouse;
import com.rw.magallanes.ide.main.MainFrame;
import com.rw.magallanes.ide.main.MainSystem;
import com.rw.magallanes.utilities.MessageType;
import com.rw.magallanes.utilities.Utilities;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;

/**
 *
 * @author Gonzalez
 */
public class DeleteCategoryAction extends AbstractAction {

    @Override
    public void actionPerformed(ActionEvent e) {
        MainSystem ms = MainSystem.getInstance();
        MainFrame mf = ms.getMainFrame();

        Category category = mf.getSelectedCategory();
        if (category != null) {

            if (Utilities.showYesNo(mf, "Se eliminaran todos los items de la categoria. Desea continuar?")) {
                Warehouse wh = mf.getWarehouse();
                wh.deleteCategory(category);
                mf.updateCategoriesTable();
                mf.updateItemsFor(null);
            }
        } else {
            Utilities.showMsg(mf, "Seleccione un item", MessageType.WARN);
        }

    }

    @Override
    public Object getValue(String key) {
        if (key.compareTo(NAME) == 0) {
            return "Eliminar Item";
        } else {
            return super.getValue(key);
        }
    }
}
